package com.lbs.jiepiaisi.base;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lbs.jiepiaisi.utils.LoggerUtil;
import com.trello.rxlifecycle2.components.RxFragment;

/**
 *
 * 时间：2017/6/16 14:03
 * 作用：Fragment扩展类
 */

public abstract class BaseFragment extends Fragment {

    //定义FragmentActivity对象
    public FragmentActivity mActivity;
    public Context mContext;
    public int page = 1;
    public int size = 10;
    /**
     * 打印TAG，类名
     */
    private String TAG = getClass().getSimpleName();
    /**
     * 此方法可以得到上下文对象
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
    }
    /**
     * 返回一个需要展示的View
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mActivity = getActivity();
        View view = initView(inflater);

        getExtras(view);
        findView(view);
        setListener(view);
        return view;
    }
    /**
     * 子类实现此抽象方法返回View进行展示
     *
     * @return
     */
    public abstract View initView(LayoutInflater inflater);
    //初始化三部曲之：获取传参
    protected abstract void getExtras(View view);
    //初始化三部曲之：查找控件
    protected abstract void findView(View view);
    //初始化三部曲之：设置监听
    protected abstract void setListener(View view);
    /**
     * 打印v级别信息
     *
     * @param msg
     */
    protected void log_v(String msg) {
        LoggerUtil.v(TAG, msg);
    }

    /**
     * 打印d级别信息
     *
     * @param msg
     */
    protected void log_d(String msg) {
        LoggerUtil.d(TAG, msg);
    }

    /**
     * 打印i级别信息
     *
     * @param msg
     */
    protected void log_i(String msg) {
        LoggerUtil.i(TAG, msg);
    }

    /**
     * 打印w级别信息
     *
     * @param msg
     */
    protected void log_w(String msg) {
        LoggerUtil.w(TAG, msg);
    }

    /**
     * 打印e级别信息
     *
     * @param msg
     */
    protected void log_e(String msg) {
        LoggerUtil.e(TAG, msg);
    }

    /**
     * 打印
     *
     * @param msg
     */
    protected void println(Object msg) {
        LoggerUtil.println(msg);
    }


}
